package de.uni_saarland.coli.doclists.test.btree;

import de.uni_saarland.coli.doclists.index.filesystem.DiscList;
import de.uni_saarland.coli.doclists.index.filesystem.FilesystemHelper;
import de.uni_saarland.coli.doclists.index.filesystem.IToBytes;

public class SimpleIToByte implements IToBytes {
	int id;
	int value;
	DiscList parentDiscList;
	
	public SimpleIToByte(int value) {
		this.value = value;
		this.id = 0;
		this.parentDiscList = null;
	}
	
	public SimpleIToByte(byte[] bytes) {
		System.out.println("R: " + bytes.length);
		this.value = FilesystemHelper.getIntFromByteArray(bytes, 0);
		this.id = 0;
		this.parentDiscList = null;
	}
	
	public void setValue(int value) {
		this.value = value;
		this.parentDiscList.updateData(this.id, this.toBytes());
	}
	
	public int getValue() {
		return this.value;
	}
	
	@Override
	public void setListIDX(int idx) {
		this.id = idx;
	}

	@Override
	public int getListIDX() {
		return this.id;
	}

	@Override
	public byte[] toBytes() {
		byte[] bytes = new byte[4];
		FilesystemHelper.addIntToByteArray(bytes, this.value, 0);
		return bytes;
	}

	@Override
	public void setDistList(DiscList list) {
		this.parentDiscList = list;		
	}

	@Override
	public String toString() {
		return this.id + " = " + this.value;
	}
}
